// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Data.Common;
using IBM.Data.DB2.Core;

namespace SnapObjects.Data.Informix
{
    public class InformixDataContext : DataContext
    {
        public InformixDataContext(IDataContextOptions dataContextOptions) :
            base(dataContextOptions)
        {
            this.AdoDbProviderFactory = new InformixAdoDbProviderFactory(this);
            this.AdoDbSqlProvider = new InformixAdoDbSqlProvider(this.ContextOptions);
            this.AdoDbSchemaProvider = new InformixAdoDbSchemaProvider(this);
        }

        public InformixDataContext(DB2Connection dbConnection) :
            base(dbConnection, new InformixDataContextOptions(String.Empty))
        {
            this.AdoDbProviderFactory = new InformixAdoDbProviderFactory(this);
            this.AdoDbSqlProvider = new InformixAdoDbSqlProvider(this.ContextOptions);
            this.AdoDbSchemaProvider = new InformixAdoDbSchemaProvider(this);
        }

        internal override IAdoDbProviderFactory AdoDbProviderFactory { get; }

        internal override IAdoDbSchemaProvider AdoDbSchemaProvider { get; }

        internal override IAdoDbSqlProvider AdoDbSqlProvider { get; }

        internal override IAdoDbConnection CreateAdoDbConnection(string connectionString)
        {
            return new InformixAdoDbConnection(connectionString, _dataContextOptions);
        }

        internal override IAdoDbConnection CreateAdoDbConnection(DbConnection dbConnection)
        {
            return new InformixAdoDbConnection((DB2Connection)dbConnection, _dataContextOptions);
        }
    }
}
